//
// Created by antler on 2018/12/19.
//

#include "UI.h"

#include "GlobalMacros.h"

#include "log.h"

#include "UIUtils.h"

const char *UI::PSEUDO::ACTIVE = "active";
const char *UI::PSEUDO::FOCUS = "focus";
const char *UI::PSEUDO::ENABLED = "enabled";
const char *UI::PSEUDO::DISABLED = "disabled";

UI *UI::g_pUI = nullptr;

UI *UI::getInstance() {
    if (!g_pUI) {
        g_pUI = new(std::nothrow)UI();
    }
    return g_pUI;
}

void UI::releaseInstance() {
    SAFE_DELETE(g_pUI);
}

UI::UI() {

}

UI::~UI() {

}

void UI::toast(const std::string &msg, int length) {
    UIUtils::toast(msg, length);
}

UIContext *UI::createContext(const std::string &layout, const std::string &style) {
    jobject juicontext = UIUtils::createContext(layout, style);
    if (juicontext) {
        UIContext *uiContext = new(std::nothrow) UIContext();
        if (uiContext) {
            uiContext->initWith(juicontext, layout, style);
            return uiContext;
        }
    }
    return nullptr;
}

void UI::registerUI(const std::string &name, const std::string &layout) {
    LOGV("UI::registerUI \nname:%s\nlayout:%s", name.c_str(), layout.c_str());
    UIUtils::registerUI(name, layout);
}
